package cn.tmall.cmm.impl;

import cn.tmall.IBannerService;
import cn.tmall.commons.enums.cms.BannerTypeEnum;
import cn.tmall.commons.service.impl.BaseServiceImpl;
import cn.tmall.dao.cms.BannerRepository;
import cn.tmall.entity.cms.Banner;
import cn.tmall.offcialsite.BannerVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

/**
 * @author YANG
 */
@Service
public class BannerServiceImpl extends BaseServiceImpl<Banner,Long, BannerRepository> implements IBannerService {
    @Autowired
    @Qualifier("bannerRepository")
    private BannerRepository bannerRepository;

    /**
     * 查询首页banner数据
     * @return
     */
    @Override
    public BannerVo queryIndexBanner(){
    return queryBanner(BannerTypeEnum.INDEX.getValue());
    }

    @Override
    public BannerVo queryBanner(String type){
        BannerVo banner = new BannerVo();
        List<Banner> bannerList = bannerRepository.findAllByType(type);
        banner.setIndex(0);
        banner.setList(bannerList);
        return  banner;
    }
}
